﻿@model PhoneBilling.Models.DiscountMgtModel
@{
    ViewBag.Title = "优惠表管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
    function del(id, name) {
        var r = confirm("确认删除优惠：" + name + "吗？");
        if (r == true) {
            window.location.href = "/Manage/DiscountDelete?id=" + id;
        }
        return false;
    }
</script>
@{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.AppendLine(string.Format("var data={{Total:{0},",Model.DiscountList.Count));
    sb.AppendLine("Rows:[");
    for(int i =0;i < Model.DiscountList.Count;i++)
    {
        var item = Model.DiscountList[i];
        if(i == 0)
        {
            sb.Append("{");
        }
        else
        {
            sb.Append(",{");
        }
        sb.Append(string.Format("ItemNo:'{0}',", item.ItemNo));
        sb.Append(string.Format("优惠名称:'{0}',", item.优惠名称));
        sb.Append(string.Format("起始时间:'{0}',", item.起始时间.ToString("HH:mm:ss")));
        sb.Append(string.Format("终止时间:'{0}',", item.终止时间.ToString("HH:mm:ss")));
        sb.Append(string.Format("折扣话类:'{0}',", item.折扣话类));
        sb.Append(string.Format("基本费折扣:'{0}',", item.基本费折扣));
        sb.Append(string.Format("附加费折扣:'{0}',", item.附加费折扣));
        sb.Append(string.Format("服务费折扣:'{0}',", item.服务费折扣));
        sb.Append(string.Format("生效日期:'{0}',", item.生效日期.ToString("yyyy-MM-dd HH:mm:ss")));
        sb.Append(string.Format("失效日期:'{0}'", item.失效日期.ToString("yyyy-MM-dd HH:mm:ss")));
        sb.Append("}");
    }
    sb.AppendLine("]};");
    string data = sb.ToString();
}
<script type="text/javascript">
    @Html.Raw(data)
    
    var menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '新增', click: newclick },
            { line: true },
            { text: '修改', click: modifyclick },
            { line: true },
            { text: '删除', click: deleteclick }
            ]
        });
    var grid;
    $(function () {

        grid = $("#maingrid").ligerGrid({
            columns: [
                { display: '优惠名称', name: '优惠名称',width:80},
                { display: '起始时间', name: '起始时间',width:80},
                { display: '终止时间', name: '终止时间',width:80},
                { display: '折扣话类', name: '折扣话类',width:120},
                { display: '基本费折扣', name: '基本费折扣',width:120},
                { display: '附加费折扣', name: '附加费折扣',width:120},
                { display: '服务费折扣', name: '服务费折扣',width:120},
                { display: '生效日期', name: '生效日期',width:140},
                { display: '失效日期', name: '失效日期',width:140}
                ],
                isScroll: false, data: data,pageSize:30,alternatingRow:true,  
                onContextmenu: function (node, e) {
            actionNodeID = node;
            menu.show({ top: e.pageY, left: e.pageX });
            return false;
        }
        }
        );resetGridHeight(grid);
        $(window).resize(function () {
                resetGridHeight(grid);
            });
    });    function newclick(item, i) {
        var path = "/Manage/DiscountEdit";
        window.location.href=path;
    }
    function modifyclick(item, i) {
        var path = "/Manage/DiscountEdit?id="+actionNodeID.data.ItemNo;
        window.location.href=path;
    }    function deleteclick(item, i) {
        del(actionNodeID.data.ItemNo,actionNodeID.data.DiscountEdit);
    }
    $(document).ready(function () {
        $("#btnNew").ligerButton(
        {
            click: function () {
                window.location.href = "/Manage/DiscountEdit";
            }
        });
        $("#btnModify").ligerButton(
        {
            click: function () {
                var row = grid.getSelectedRow();
                if(row != null)
                {
                    var path = "/Manage/DiscountEdit?id="+row.ItemNo;
                    window.location.href=path;
                }
            }
        });

        $("#btnDelete").ligerButton(
        {
            click: function () {
                var row = grid.getSelectedRow();
                if(row != null)
                {
                    del(row.ItemNo,row.优惠名称);
                }
            }
        });
    });
</script>

<div class="system_toolbar">
    <input type="button" id="btnNew" value="新增" />
    <input type="button" id="btnModify" value="修改" />
    <input type="button" id="btnDelete" value="删除" />
</div>
<div id="maingrid"></div>
@*<p id="btn-create" class="box"><a href="/Manage/DiscountEdit"><span>新增优惠</span></a></p>*@
@*@{
    var grid = new WebGrid(source: Model.DiscountList, rowsPerPage: 30);
}
@grid.GetHtml(
    alternatingRowStyle: "bg",
    columns:grid.Columns
    (
        grid.Column("优惠名称","优惠名称"),
        grid.Column("起始时间","起始时间"),
        grid.Column("终止时间","终止时间"),
        grid.Column("折扣话类","折扣话类"),
        grid.Column("基本费折扣","基本费折扣"),
        grid.Column("附加费折扣","附加费折扣"),
        grid.Column("服务费折扣","服务费折扣"),
        grid.Column(format:(item)=> Html.ActionLink("修改","DiscountEdit",new {id=item.ItemNo})),
        grid.Column(format: (item) => Html.Raw(string.Format("<a href='javascript:' onclick=\"del('{0}','{1}')\">删除</a>", item.ItemNo, item.优惠名称)))
    )
)*@
